package dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.metodo_ahp.usuario.aplicacionmetodoahp.R;

import adapters.ExpListAdapterCompararAlternativas;
import gestores.GestorModeloAHP;
import modelo.Comparacion;
import modelo.Item;

/**
 * Created by Usuario on 19/10/2014.
 */

public class DlgCompararAlternativas extends DialogFragment {

    int idCriterio;
    TextView tituloCriterio;
    GestorModeloAHP gestorModelo;

    public void setGestorModelo() {
        this.gestorModelo =(GestorModeloAHP) getActivity().getApplication();
    }

    public static DlgCompararAlternativas newInstance(GestorModeloAHP gestorModelo, int idCriterio) {

        DlgCompararAlternativas frag = new DlgCompararAlternativas();
        Bundle args = new Bundle();
        frag.setIdCriterio(idCriterio);
        //frag.setGestorModelo();
        return frag;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View v = inflater.inflate(R.layout.step_4_dlg_comp_alt,null);


       gestorModelo = (GestorModeloAHP) getActivity().getApplication();

       Item criterio = gestorModelo.getItemById(idCriterio,true);


        ExpandableListView expLstAlternativas = (ExpandableListView) v.findViewById(R.id.expLstCompAlternativas);

        ExpListAdapterCompararAlternativas adapterAlt = new ExpListAdapterCompararAlternativas(this.getActivity(), gestorModelo.buildDataParentsStep4(idCriterio), gestorModelo.buildDataChildrenStep4(idCriterio),criterio);
        expLstAlternativas.setAdapter(adapterAlt);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        //Obtengo el inflater

        //Inflar y setear el layout.
        builder.setView(v)
                //Botones.
                .setPositiveButton(R.string.action_next,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int whichButton) {

                            }
                        })
                .setNegativeButton(R.string.action_previous,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int whichButton) {
                            }
                        });
        //tituloCriterio = (TextView) this.getView().findViewById(R.id.step_4_dlg_comp_alt);
        //tituloCriterio.setText((CharSequence) criterio.getNombre());
        return builder.create();
    }

    public GestorModeloAHP getGestorModelo() {
        return gestorModelo;
    }



    public int getIdCriterio() {
        return idCriterio;
    }

    public void setIdCriterio(int idCriterio) {
        this.idCriterio = idCriterio;
    }
}
